package cn.com.yusys.yusp.admin.service;

import cn.com.yusys.yusp.admin.domain.*;
import cn.com.yusys.yusp.admin.repository.mapper.*;
import cn.com.yusys.yusp.commons.exception.MessageConstants;
import cn.com.yusys.yusp.commons.exception.YuspException;
import cn.com.yusys.yusp.commons.mapper.CommonMapper;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.util.DateUtil;
import cn.com.yusys.yusp.commons.util.StringUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0.0
 * @项目名称: yusp-admin
 * @类名称: AdminSmLogicSyService
 * @类描述: 逻辑系统管理服务层
 * @功能描述:
 * @创建人: dusong@yusys.com.cn
 * @创建时间: 2017-12-19 13:41
 * @修改备注:
 * @修改记录: 修改时间 修改人员 修改原因
 * -------------------------------------------------------------
 * @Copyright (c) 2017宇信科技-版权所有
 */
@Service
public class AdminSmLogicSysService extends CommonService {
    private final static Logger logger = LoggerFactory.getLogger(AdminSmLogicSysService.class);
    private static final String DEFAULT_USER = "_admin"; // 默认登录代码后缀 _admin
    private static final String DEFAULT_ROLE_LEVEL = "2"; // 默认管理员登录 2
    private static final String DEFAULT_ROLE_STATUS = "A"; // 默认角色状态 A 正常
    private static final String DEFAULT_AUTH_OBJ_TYPE = "R"; // 默认授权类 R 角色
    private static final String DEFAULT_AUTH_RES_TYPE = "M"; // 默认资源类型 M 菜单
    private static final String DEFAULT_CRELSTRA_RULE = "LOGIN_FIRST_RULE";

    @Autowired
    private AdminSmLogicSysMapper adminSmLogicSyMapper;

    @Autowired
    private AdminSmCrelStraMapper adminSmCrelStraMapper;

    @Autowired
    private MessageProviderService messageProviderService;

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Autowired
    private AdminSmMenuMapper adminSmMenuMapper;

    @Autowired
    private AdminSmAuthRecoMapper adminSmAuthRecoMapper;

    /**
     * @属性名称: menuIdRel
     * @属性描述: 菜单主键新老映射关系
     * @since 1.0.0
     */
    private Map<String, String> menuIdRel;

    @SuppressWarnings("rawtypes")
    @Override
    protected CommonMapper getMapper() {
        return this.adminSmLogicSyMapper;
    }

    /**
     * @方法名称: selectByModel
     * @方法描述: 首页查询
     * @参数与返回说明:
     * @算法描述:
     */
    @SuppressWarnings("unchecked")
    @Override
    public <T> List<T> selectByModel(QueryModel model) {
        PageHelper.startPage(model.getPage(), model.getSize());
        List<Map<String, String>> list = this.adminSmLogicSyMapper.getLogicSysInfo(model);
        PageHelper.clearPage();
        return (List<T>) list;
    }

    /**
     * @方法名称: deleteLogicAndCrelInfo
     * @方法描述: 删除逻辑系统和认证策略信息
     * @参数与返回说明:
     * @算法描述:
     */
    @Transactional(readOnly = false, rollbackFor = {Exception.class, RuntimeException.class})
    public int deleteLogicAndCrelInfo(String sysId) {

        int result = adminSmLogicSyMapper.deleteByPrimaryKey(sysId);

        //删除认证信息
        AdminSmCrelStra adminSmCrelStra = new AdminSmCrelStra();
        adminSmCrelStra.setSysId(sysId);
        int crelResult = adminSmCrelStraMapper.delete(adminSmCrelStra);

        //删除菜单信息
        AdminSmMenu adminSmMenu = new AdminSmMenu();
        adminSmMenu.setSysId(sysId);
        int menuResult = adminSmMenuMapper.delete(adminSmMenu);

        //删除授权信息
        AdminSmAuthReco adminSmAuthReco = new AdminSmAuthReco();
        adminSmAuthReco.setSysId(sysId);
        int authRecoResult = adminSmAuthRecoMapper.delete(adminSmAuthReco);

        //删除角色       安全考虑，在页面模块删除
        //删除角色关系  安全考虑，在页面模块删除

        logger.info("Delete logical system,sysId:{},result:{}", sysId, result);
        logger.info("Delete authentication policy information,sysId:{},result:{}", sysId, crelResult);
        logger.info("Delete menu information,sysId:{},result:{}", sysId, menuResult);
        logger.info("Delete authorization information,sysId:{},result:{}", sysId, authRecoResult);
        return result;
    }

    @Transactional(readOnly = true)
    public List<Map<String, String>> getLogicSysKeyValue() {
        return this.adminSmLogicSyMapper.getLogicSysKeyValue(new HashMap<String, String>());
    }

    /**
     * @方法名称: insertAndCopy
     * @方法描述: 初始化逻辑系统信息，对逻辑系统添加事务注解，避免占用太多连接
     * @参数与返回说明:
     * @算法描述: 复制超级管理系统的用户、角色、菜单、授权信息，作为新逻辑系统的初始数据
     */
    @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
    public AdminSmLogicSys insertAndCopy(AdminSmLogicSysVO adminSmLogicSysVo) {
        menuIdRel = new HashMap<String, String>();

        logger.info("Initialize logical system information:{}", adminSmLogicSysVo);
        SqlSession session = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);

        String opUserId = adminSmLogicSysVo.getUserId();
        String oldSysId = adminSmLogicSysVo.getOldSysId();
        String sysCode = adminSmLogicSysVo.getSysCode().toUpperCase();
        String sysName = adminSmLogicSysVo.getSysName();
        String funcId = adminSmLogicSysVo.getFuncId();

        AdminSmLogicSys adminSmLogicSys = new AdminSmLogicSys();
        BeanUtils.copyProperties(adminSmLogicSysVo, adminSmLogicSys);

        AdminSmLogicSysMapper logicSysMapper = session.getMapper(AdminSmLogicSysMapper.class);
        AdminSmCrelStraMapper crelStraMapper = session.getMapper(AdminSmCrelStraMapper.class);
        AdminSmUserMapper userMapper = session.getMapper(AdminSmUserMapper.class);
        AdminSmMenuMapper menuMapper = session.getMapper(AdminSmMenuMapper.class);
        AdminSmRoleMapper roleMapper = session.getMapper(AdminSmRoleMapper.class);
        AdminSmUserRoleRelMapper userRoleRelMapper = session.getMapper(AdminSmUserRoleRelMapper.class);
        AdminSmAuthRecoMapper authRecoMapper = session.getMapper(AdminSmAuthRecoMapper.class);

        logger.info("Initialize basic information");
        //初始逻辑系统ID
        adminSmLogicSys.setSysId(StringUtil.getUUID());

        logger.info("Check data validity");
        //检查数据有效性
        if (!checkSysInfo("sysName", sysName, logicSysMapper)) {
            logger.error("Failed to check data validity, system name already exists");
            throw new YuspException(messageProviderService.getMessage(String.valueOf(MessageConstants.RET_CODE_20100005)));
        }

        if (!checkSysInfo("sysCode", sysCode, logicSysMapper)) {
            logger.error("Failed to check data validity, system code already exists");
            throw new YuspException(messageProviderService.getMessage(String.valueOf(MessageConstants.RET_CODE_20100006)), sysCode);
        }

        //初始化用户信息 不新增用户，为老用户增加新角色
//        AdminSmUser newAdminSmuser = makeUser(opUserId, sysCode, userMapper);
//        if (!checkNomalInfo("loginCode", newAdminSmuser.getLoginCode(), userMapper)) {
//            logger.error("检查数据有效性失败，用户登录代码[{}]已存在", newAdminSmuser.getLoginCode());
//            throw new YuspException(MessageProvider.getMessage("100004"), newAdminSmuser.getLoginCode());
//        }
        AdminSmUser newAdminSmuser = userMapper.selectByPrimaryKey(opUserId);

        //初始化角色信息
        AdminSmRole adminSmRole = makeRole(opUserId, newAdminSmuser.getLoginCode(), sysCode, newAdminSmuser.getOrgId());
        if (!checkNomalInfo("roleCode", adminSmRole.getRoleCode(), roleMapper)) {
            logger.error("Failed to check data validity, user role code [{}] already exists", adminSmRole.getRoleCode());
            throw new YuspException(messageProviderService.getMessage(String.valueOf(MessageConstants.RET_CODE_20100009)), adminSmRole.getRoleCode());
        }

        //初始化用户角色关系
        AdminSmUserRoleRel adminSmUserRoleRel = makeUserRoleRel(newAdminSmuser.getUserId(), adminSmRole.getRoleId(), opUserId);

        //查询原角色信息，复制超级管理员的账号信息
//        AdminSmUserRoleRel oldAdminSmUserRoleRel = new AdminSmUserRoleRel();
//        oldAdminSmUserRoleRel.setUserId(adminSmLogicSysVo.getUserId());
//        oldAdminSmUserRoleRel = userRoleRelMapper.selectByPrimaryKey(oldAdminSmUserRoleRel).get(0);

        //初始化菜单列表，复制系统管理的所有菜单
        List<AdminSmMenu> adminSmMenuList = copyMenu(oldSysId, adminSmLogicSys.getSysId(), menuMapper, funcId);

        //初始化授权信息
        List<AdminSmAuthReco> adminSmAuthRecoList = copyResReco(oldSysId, adminSmLogicSys.getSysId(),
                adminSmLogicSysVo.getRoleId(), adminSmRole.getRoleId(), opUserId, authRecoMapper);

        List<AdminSmCrelStra> adminSmCrelStraList = makeCrelStra(adminSmLogicSys.getSysId(), opUserId);

        //注意，事务内不允许做查询操作，否则无法做事务回滚
        try {
            //持久化逻辑系统 不新增用户，为老用户增加新角色
            logicSysMapper.insert(adminSmLogicSys);
            logger.info("Completed logical system initialization: {}", adminSmLogicSys);

            //持久化用户
//            userMapper.insertSelective(newAdminSmuser);
//            logger.info("已完成用户初始化:{}", newAdminSmuser);

            //持久化角色
            roleMapper.insert(adminSmRole);
            logger.info("Completed role initialization: {}", adminSmRole);

            //持久化用户角色关系
            userRoleRelMapper.insert(adminSmUserRoleRel);
            logger.info("Completed user role relationship initialization: {}", adminSmUserRoleRel);

            //持久化菜单信息
            for (AdminSmMenu adminSmMenu : adminSmMenuList) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Menu information: {}", adminSmMenu);
                }
                
                menuMapper.insertSelective(adminSmMenu);
            }
            logger.info("Completed menu information initialization");

            //持久化授权信息
            for (AdminSmAuthReco adminSmAuthReco : adminSmAuthRecoList) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Authorization information: {}", adminSmAuthReco);
                }
                authRecoMapper.insertSelective(adminSmAuthReco);
            }
            logger.info("Completed authorization information initialization");

            //持久化认证策略
            for (AdminSmCrelStra adminSmCrelStra : adminSmCrelStraList) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication information: {}", adminSmCrelStra);
                }
                crelStraMapper.insertSelective(adminSmCrelStra);
            }
            logger.info("Completed authentication information initialization");

            session.commit();
            session.clearCache();

        } catch (Exception e) {
            // 没有提交的数据可以回滚
            logger.error("Failed to initialize logical system, error message: {}", e.getMessage());
            session.rollback();
            throw e;
        } finally {
            session.close();
        }

        logger.info("Logical system created successfully");
        return adminSmLogicSys;
    }

    /**
     * @方法名称: makeUser
     * @方法描述: 构建新的管理员
     * @参数与返回说明:
     * @算法描述:
     */
    public AdminSmUser makeUser(String opUserId, String sysCode, AdminSmUserMapper adminSmUserMapper) {
        if (logger.isDebugEnabled()) {
            logger.debug("opUserId:{},sysCode{}", opUserId, sysCode);
        }
        AdminSmUser newAdminSmuser = new AdminSmUser();
        newAdminSmuser = adminSmUserMapper.selectByPrimaryKey(opUserId);
        newAdminSmuser.setUserId(StringUtil.getUUID());
        newAdminSmuser.setLoginCode(sysCode + DEFAULT_USER);
        newAdminSmuser.setLastChgUsr(opUserId);
        newAdminSmuser.setLastChgDt(DateUtil.formatDateTimeByDef());
        newAdminSmuser.setLastEditPassTime("");
        newAdminSmuser.setLastLoginTime("");
        //newAdminSmuser.setUserPassword("");
        return newAdminSmuser;
    }

    /**
     * @方法名称: makeRole
     * @方法描述: 构建新的角色
     * @参数与返回说明:
     * @算法描述:
     */
    private AdminSmRole makeRole(String userId, String newLoginCode, String sysCode, String orgId) {
        if (logger.isDebugEnabled()) {
            logger.debug("newLoginCode:{},userId{},sysCode:{},orgId:{}", newLoginCode, userId, sysCode, orgId);
        }
        AdminSmRole adminSmRole = new AdminSmRole();

        adminSmRole.setRoleCode(sysCode + DEFAULT_USER);
        adminSmRole.setRoleName(sysCode + "系统管理员");
        adminSmRole.setRoleSts(DEFAULT_ROLE_STATUS);
        adminSmRole.setRoleLevel(DEFAULT_ROLE_LEVEL);
        adminSmRole.setOrgId(orgId);
        adminSmRole.setRoleId(StringUtil.getUUID());
        adminSmRole.setLastChgUsr(userId);
        adminSmRole.setLastChgDt(DateUtil.formatDateTimeByDef());
        return adminSmRole;
    }

    /**
     * @方法名称: makeUserRoleRel
     * @方法描述: 初始化用户角色关系
     * @参数与返回说明:
     * @算法描述:
     */
    private AdminSmUserRoleRel makeUserRoleRel(String newUserId, String newRoleId, String opUserId) {
        if (logger.isDebugEnabled()) {
            logger.debug("newUserId:{},newRoleId{},opUserId:{}", newUserId, newRoleId, opUserId);
        }
        AdminSmUserRoleRel adminSmUserRoleRel = new AdminSmUserRoleRel();
        adminSmUserRoleRel.setUserId(newUserId);
        adminSmUserRoleRel.setRoleId(newRoleId);
        adminSmUserRoleRel.setRelSts(DEFAULT_ROLE_STATUS);
        adminSmUserRoleRel.setLastChgDt(DateUtil.formatDateTimeByDef());
        adminSmUserRoleRel.setLastChgUsr(opUserId);
        adminSmUserRoleRel.setUserRoleRelId(StringUtil.getUUID());
        return adminSmUserRoleRel;
    }

    /**
     * @方法名称: makeMenu
     * @方法描述: 复制菜单
     * @参数与返回说明:
     * @算法描述:
     */
    private List<AdminSmMenu> copyMenu(String oldSysId, String newSysId, AdminSmMenuMapper adminSmMenuMapper, String funcId) {
        if (logger.isDebugEnabled()) {
            logger.debug("oldSysId:{},newSysId{}", oldSysId, newSysId);
        }
        AdminSmMenu adminSmMenuOld = new AdminSmMenu();
        adminSmMenuOld.setSysId(oldSysId);
        QueryModel queryModel = new QueryModel();

        try {
            Map<String, String> paramMap = new HashMap<String, String>();
            paramMap.put("sysId", oldSysId);
            ObjectMapper jsonObj = new ObjectMapper();
            if (logger.isDebugEnabled()) {
                logger.debug("paramMap:{}", paramMap);
            }
            queryModel.setCondition(jsonObj.writeValueAsString(paramMap));
        } catch (Exception e) {
            logger.error("copyMenu error, message:{}", e.getMessage());
            e.printStackTrace();
        }

        List<AdminSmMenu> adminSmMenuList = adminSmMenuMapper.selectByModel(queryModel);

        //移除逻辑系统管理模块的复制
        AdminSmMenu logicSysMenu = null;
        for (AdminSmMenu adminSmMenu : adminSmMenuList) {
            if ("beb23fb37bc548b39b52d938f75470fe".equals(adminSmMenu.getFuncId()) ||
                    "逻辑系统管理".equals(adminSmMenu.getMenuName())) {
                logicSysMenu = adminSmMenu;
                break;
            }
        }
        adminSmMenuList.remove(logicSysMenu);

        //如果新增逻辑系统配置了首页，则将首页funcId替换成新的funcId
        if (funcId != null && !funcId.equals("")) {
            for (AdminSmMenu adminSmMenu : adminSmMenuList) {
                if ("dashboard".equals(adminSmMenu.getFuncId()) ||
                        "首页".equals(adminSmMenu.getMenuName())) {
                    adminSmMenu.setFuncId(funcId);
                    break;
                }
            }
        }

        for (AdminSmMenu adminSmMenu : adminSmMenuList) {
            String newMenuId;

            // 记录menuId新老关系
            if (!menuIdRel.containsKey(adminSmMenu.getMenuId())) {
                newMenuId = StringUtil.getUUID();
                menuIdRel.put(adminSmMenu.getMenuId(), newMenuId);
            } else {
                newMenuId = menuIdRel.get(adminSmMenu.getMenuId());
            }
            adminSmMenu.setMenuId(newMenuId);
            adminSmMenu.setSysId(newSysId);
        }

        // 更新所有老的menuId；
        for (AdminSmMenu adminSmMenu : adminSmMenuList) {
            // 如果有对应关系，才做菜单关系更新
            if (menuIdRel.containsKey(adminSmMenu.getUpMenuId())) {
                adminSmMenu.setUpMenuId(menuIdRel.get(adminSmMenu.getUpMenuId()));
            }
            if (logger.isDebugEnabled()) {
                logger.debug("adminSmMenu:{}", adminSmMenu);
            }
        }

        return adminSmMenuList;
    }

    /**
     * @方法名称: makeResReco
     * @方法描述: 复制授权信息
     * @参数与返回说明:
     * @算法描述:
     */
    private List<AdminSmAuthReco> copyResReco(String oldSysId, String newSysId, String oldRoleId, String newRoleId, String opUserId, AdminSmAuthRecoMapper adminSmAuthRecoMapper) {
        if (logger.isDebugEnabled()) {
            logger.debug("oldSysId:{}, newSysId:{}, oldRoleId:{}, newRoleId:{}, opUserId:{}", oldSysId, newSysId, oldRoleId, opUserId);
        }
        AdminSmAuthReco oldAdminSmAuthReco = new AdminSmAuthReco();
        oldAdminSmAuthReco.setSysId(oldSysId);
        oldAdminSmAuthReco.setAuthobjType(DEFAULT_AUTH_OBJ_TYPE);
        oldAdminSmAuthReco.setAuthobjId(oldRoleId);

        List<AdminSmAuthReco> adminSmAuthRecoList = adminSmAuthRecoMapper.select(oldAdminSmAuthReco);
        for (AdminSmAuthReco adminSmAuthReco : adminSmAuthRecoList) {
            // 菜单授权类数据，修改菜单ID为新的ID
            if (DEFAULT_AUTH_RES_TYPE.equals(adminSmAuthReco.getAuthresType())) {
                if (menuIdRel.containsKey(adminSmAuthReco.getAuthresId())) {
                    adminSmAuthReco.setAuthresId(menuIdRel.get(adminSmAuthReco.getAuthresId()));
                }
            }

            if (menuIdRel.containsKey(adminSmAuthReco.getMenuId())) {
                adminSmAuthReco.setMenuId(menuIdRel.get(adminSmAuthReco.getMenuId()));
            }

            adminSmAuthReco.setAuthRecoId(StringUtil.getUUID());
            adminSmAuthReco.setSysId(newSysId);
            adminSmAuthReco.setAuthobjId(newRoleId);
            adminSmAuthReco.setLastChgDt(DateUtil.formatDateTimeByDef());
            adminSmAuthReco.setLastChgUsr(opUserId);

            if (logger.isDebugEnabled()) {
                logger.debug("adminSmAuthReco:{}", adminSmAuthReco);
            }
        }

        return adminSmAuthRecoList;
    }

    /**
     * @方法名称: makeCrelStra
     * @方法描述: 初始化安全策略
     * @参数与返回说明:
     * @算法描述:
     */
    private List<AdminSmCrelStra> makeCrelStra(String newSysId, String opUserId) {
        if (logger.isDebugEnabled()) {
            logger.debug("newSysId:{}, opUserId:{}", newSysId, opUserId);
        }

        //强制修改密码
        List<AdminSmCrelStra> AdminSmCrelStraList = new ArrayList<AdminSmCrelStra>();
        AdminSmCrelStra adminSmCrelStra = new AdminSmCrelStra();

        adminSmCrelStra.setActionType("3");  //1冻结, 2禁止, 3警告
        adminSmCrelStra.setCerlName(DEFAULT_CRELSTRA_RULE);//首次登录，强制修改密码
        adminSmCrelStra.setCrelDetail("1"); //1是  
        adminSmCrelStra.setCrelId(StringUtil.getUUID());
        adminSmCrelStra.setEnableFlag("1");  //1 是, 2 否
        adminSmCrelStra.setLastChgDt(DateUtil.formatDateTimeByDef());
        adminSmCrelStra.setLastChgUsr(opUserId);
        adminSmCrelStra.setSysId(newSysId);
        AdminSmCrelStraList.add(adminSmCrelStra);

        return AdminSmCrelStraList;
    }


    /**
     * @方法名称: checkSysCode
     * @方法描述: 检查逻辑系统名称 或逻辑系统代码已存在
     * @参数与返回说明:
     * @算法描述:
     */
    private boolean checkSysInfo(String columnName, String columnValue, AdminSmLogicSysMapper adminSmLogicSysMapper) {
        QueryModel queryModel = new QueryModel();

        try {
            Map<String, String> paramMap = new HashMap<String, String>();
            paramMap.put(columnName, columnValue);
            ObjectMapper jsonObj = new ObjectMapper();
            if (logger.isDebugEnabled()) {
                logger.debug("paramMap:{}", paramMap);
            }

            queryModel.setCondition(jsonObj.writeValueAsString(paramMap));
        } catch (Exception e) {
            logger.error("checkSysInfo error, message:{}", e.getMessage());
            e.printStackTrace();
            return false;
        }

        List<AdminSmLogicSys> adminSmLogicSysList = adminSmLogicSysMapper.selectByModel(queryModel);
        if (adminSmLogicSysList != null && adminSmLogicSysList.size() > 0) {
            if (logger.isDebugEnabled()) {
                logger.debug("adminSmLogicSysList:{}", adminSmLogicSysList);
            }
            return false;
        }
        return true;
    }

    /**
     * @方法名称: checkSysCode
     * @方法描述: 检查信息是否存在
     * @参数与返回说明:
     * @算法描述:
     */
    @SuppressWarnings("rawtypes")
    private boolean checkNomalInfo(String columnName, String columnValue, CommonMapper mapper) {
        QueryModel queryModel = new QueryModel();

        try {
            Map<String, String> paramMap = new HashMap<String, String>();
            paramMap.put(columnName, columnValue);
            ObjectMapper jsonObj = new ObjectMapper();
            if (logger.isDebugEnabled()) {
                logger.debug("paramMap:{}", paramMap);
            }

            queryModel.setCondition(jsonObj.writeValueAsString(paramMap));
        } catch (Exception e) {
            logger.error("checkUserInfo error, message:{}", e.getMessage());
            e.printStackTrace();
            return false;
        }

        List list = mapper.selectByModel(queryModel);
        if (list != null && list.size() > 0) {
            if (logger.isDebugEnabled()) {
                logger.debug("list:{}", list);
            }
            return false;
        }
        return true;
    }

    /**
     * @方法名称: queryIndex
     * @方法描述: 编辑逻辑系统时查询可设置的首页
     * @参数与返回说明:
     * @算法描述:
     */
    @Transactional(readOnly = true)
    public List<Map<String, String>> queryIndex(QueryModel model) {
        PageHelper.startPage(model.getPage(), model.getSize());
        List<Map<String, String>> list = this.adminSmLogicSyMapper.queryIndex(model);
        PageHelper.clearPage();
        return list;
    }

    /**
     * @方法名称: queryIndex
     * @方法描述: 修改逻辑系统
     * @参数与返回说明:
     * @算法描述:
     */
    @Transactional(readOnly = false, rollbackFor = {Exception.class, RuntimeException.class})
    public int updateSysInfo(AdminSmLogicSys t, String funcId) {
        int i = 0;
        i = this.adminSmLogicSyMapper.updateByPrimaryKey(t);
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("funcId", funcId);
        paramMap.put("sysId", t.getSysId());
        i = i + this.adminSmLogicSyMapper.updateFuncId(paramMap);
        return i;
    }
}
